package part15;

/**
 * @author wcj
 * @Date 2021/5/30 17:14
 * @Version 1.0
 */
public class Part1530<T> {
    private int index = 0;
    private Object[] storage;

    public Part1530(int size) {
        storage = new Object[size];
    }

    public void push(T item) {
        storage[index++] = item;
    }

    public T pop() {
        // 这里警告是因为泛型的第一个边界就是Object
        return (T) storage[--index];
    }

    public static class GenericCast {
        public static final int SIZE = 10;

        public static void main(String[] args) {
            Part1530<String> stringPart1530 = new Part1530<>(SIZE);
            for (String s : "A B C D E F G H".split(" ")) {
                stringPart1530.push(s);
            }
            for (int i = 0; i < SIZE; i++) {
                System.out.println(stringPart1530.pop());
            }
        }
    }
}
